/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Matrimonial;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Bharath
 */
public class MarRegister extends HttpServlet {

    Connection con;
    MarRegisterBean rbean;
    MarRegisterDao marDao;
    private boolean b;
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    java.util.Date date = new java.util.Date();
    private String todaysdate;

    /* constructor starts */

    public MarRegister() {
        rbean = new MarRegisterBean();
        marDao =new MarRegisterDao();
     }
    /* constructor ends */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            System.out.println(" ---------- In Matrimonial registration servlet --------------- ");
            HttpSession hs = request.getSession(true);
            String memid = (String) hs.getAttribute("memid");
            System.out.println("member id is " + memid);
            rbean.setMemid(memid);
            rbean.setMatchfor(request.getParameter("matchfor"));
            rbean.setMname(request.getParameter("mname"));
            rbean.setMsname(request.getParameter("msname"));
            rbean.setMgen(request.getParameter("gender"));
            rbean.setMdob(request.getParameter("dob"));
            rbean.setMstat(request.getParameter("mstat"));
            rbean.setMage(request.getParameter("age"));
            System.out.print("---------------> "+rbean.getMage());
            rbean.setMht(request.getParameter("height"));
            rbean.setReligion(request.getParameter("religion"));
            rbean.setMcaste(request.getParameter("caste"));
            rbean.setMlang(request.getParameter("mtongue"));
            rbean.setBtype(request.getParameter("btype"));
            rbean.setComplex(request.getParameter("complex"));
            rbean.setSelf_desc(request.getParameter("self_desc"));
            rbean.setMadd(request.getParameter("addr"));
            rbean.setMcountry(request.getParameter("country"));
            rbean.setMstate(request.getParameter("state"));
            rbean.setMdist(request.getParameter("district"));
            rbean.setMcity(request.getParameter("city"));
            rbean.setMorg(request.getParameter("org"));
            rbean.setMqual(request.getParameter("qual"));
            rbean.setMprof(request.getParameter("prof"));
            rbean.setMemail(request.getParameter("email"));
            rbean.setMmob(request.getParameter("mobile"));
            rbean.setMsal(request.getParameter("annual"));
            // Todays date 
            todaysdate = dateFormat.format(date);
            System.out.println("Current Date Time : " + todaysdate);
            rbean.setRegdate(todaysdate);
            System.out.println("in servlet ");
            // calling insert method
            b = marDao.insert(rbean);
            if (b == true) {
                out.println("<script language = 'javascript'> alert('Registration success'); location = 'Matrimonial/MatrUserHome.jsp';</script>");
            }
             else {
                out.println("<script>alert('Registration Failed');location = 'Matrimonial/MarReg.jsp'</script>");
            }
        } catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }

      @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (Exception ex) {
            Logger.getLogger(MarRegister.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

   
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (Exception ex) {
            Logger.getLogger(MarRegister.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
